#delimit ;
set more off;
pause on;
clear;

/*****************************************************************************/
/* ABOUT THIS FILE */
/*****************************************************************************/

/*
REVISED December 1 2020

CONTENTS
1. FIGURE 1: Weekly Covid-19 Infections and Articles--EXPORTED FIGURES
2. Import Coded Editorials csv File and Make Variables
3. TABLE A1. Numbers of Editorials by Newspaper--DATA USED TO CONSTRUCT TABLE
4. TABLE A3. Summary statistics of independent variables
5. TABLE A4. Logit Table: Impact of crisis abatement period on tone and framing--EXPORTED AS TABLE
6. FIGURE 2. Predicted probabilities of tone and framing levels for crisis breakout and abatement periods--EXPORTED AS FIGURE
7. TABLE 1: Alarming Tone Across Cases--DATA USED TO CONSTRUCT TABLE
8. TABLE 2: Consequence Frames Across Cases--DATA USED TO CONSTRUCT TABLE
9. TABLE 3: Responsibility Frames Across Cases--DATA USED TO CONSTRUCT TABLE
10. TABLE 4: Action Frames Across Cases--DATA USED TO CONSTRUCT TABLE
*/

/*****************************************************************************/
/* 1. FIGURE 1: Weekly Covid-19 Infections and Articles */
/*****************************************************************************/

insheet using "counts.csv";

/* Date */
gen year = 2020;
gen date = mdy(wkstart_m, wkstart_d,  year);
format date %td;

/* Totals */
gen art_korea = art_kt + art_kh;
gen art_china = art_gt + art_cd;
gen art_hk = art_sc;
gen art_taiwan = art_tt;

gen ed_korea = ed_kt + ed_kh;
gen ed_china = ed_gt + ed_cd;
gen ed_hk = ed_sc;
gen ed_taiwan = ed_tt;

/* Make a Total Weekly Vars */
gen art_tot = art_korea + art_china + art_hk + art_taiwan;
gen ed_tot = ed_korea + ed_china + ed_hk + ed_taiwan;
gen covid_tot = covid_korea + covid_china + covid_hk + covid_taiwan;


/* China */
twoway
(line covid_china week)
(line art_china week, yaxis(2)),
title(China) name(china, replace)
ytitle("") ylabel(#6, labsize(small) labcolor(navy))
ytitle("", axis(2)) ylabel(#6, labsize(small) labcolor(maroon) axis(2))
xtitle(Week) xlabel(#26, labsize(small))
legend(order(1 "Number of Infections" 2 "Number of Articles") size(small))
xsize(3) ysize(2.5);
graph export "china_chart.pdf", as(pdf) replace;

/* Hong Kong */
twoway
(line covid_hk week)
(line art_hk week, yaxis(2)),
title(Hong Kong) name(hk, replace)
ytitle("") ylabel(#8, labsize(small) labcolor(navy))
ytitle("", axis(2)) ylabel(#6, labsize(small) labcolor(maroon) axis(2))
xtitle(Week) xlabel(#26, labsize(small))
legend(order(1 "Number of Infections" 2 "Number of Articles") size(small))
xsize(3) ysize(2.5);
graph export "hk_chart.pdf", as(pdf) replace;

/* Taiwan */
twoway
(line covid_taiwan week)
(line art_taiwan week, yaxis(2)),
title(Taiwan) name(taiwan, replace)
ytitle("") ylabel(#6, labsize(small) labcolor(navy))
ytitle("", axis(2)) ylabel(#6, labsize(small) labcolor(maroon) axis(2))
xtitle(Week) xlabel(#26, labsize(small))
legend(order(1 "Number of Infections" 2 "Number of Articles") size(small))
xsize(3) ysize(2.5);
graph export "taiwan_chart.pdf", as(pdf) replace;

/* Korea */
twoway
(line covid_korea week)
(line art_korea week, yaxis(2)),
title(Korea) name(korea, replace)
ytitle("") ylabel(#8, labsize(small) labcolor(navy))
ytitle("", axis(2)) ylabel(#6, labsize(small) labcolor(maroon) axis(2))
xtitle(Week) xlabel(#26, labsize(small))
legend(order(1 "Number of Infections" 2 "Number of Articles") size(small))
xsize(3) ysize(2.5);
graph export "korea_chart.pdf", as(pdf) replace;

/* All */
twoway
(line covid_tot week)
(line art_tot week, yaxis(2)),
title(Total) name(tot, replace)
ytitle("") ylabel(#6, labsize(small) labcolor(navy))
ytitle("", axis(2)) ylabel(#6, labsize(small) labcolor(maroon) axis(2))
xtitle(Week) xlabel(#26, labsize(small))
legend(order(1 "Number of Infections" 2 "Number of Articles") size(small))
xsize(3) ysize(2.5);
graph export "allcases_chart.pdf", as(pdf) replace;

clear;

/*****************************************************************************/
/* 2. IMPORT CODED EDITORIALS CSV FILE & MAKE VARS */
/*****************************************************************************/

insheet using "data.csv";

/* Date */
gen year = 2020;
gen date = mdy(month, day,  year);
format date %td;

/* Week */
gen week = 1;
replace week = 2 if date > td(07jan2020);
replace week = 3 if date > td(14jan2020);
replace week = 4 if date > td(21jan2020);
replace week = 5 if date > td(28jan2020);
replace week = 6 if date > td(04feb2020);
replace week = 7 if date > td(11feb2020);
replace week = 8 if date > td(18feb2020);
replace week = 9 if date > td(25feb2020);
replace week = 10 if date > td(03mar2020);
replace week = 11 if date > td(10mar2020);
replace week = 12 if date > td(17mar2020);
replace week = 13 if date > td(24mar2020);
replace week = 14 if date > td(31mar2020);
replace week = 15 if date > td(07apr2020);
replace week = 16 if date > td(14apr2020);
replace week = 17 if date > td(21apr2020);
replace week = 18 if date > td(28apr2020);
replace week = 19 if date > td(05may2020);
replace week = 20 if date > td(12may2020);
replace week = 21 if date > td(19may2020);
replace week = 22 if date > td(26may2020);
replace week = 23 if date > td(02jun2020);
replace week = 24 if date > td(09jun2020);
replace week = 25 if date > td(16jun2020);
replace week = 26 if date > td(23jun2020);

/* Create Crisis Breakout and Crisis Abatement Periods */
gen end_p = "breakout";
replace end_p = "abatement" if country == "China" & week > 10; // wk10=618 Wk11=184, a few hundred more until week 17=89
replace end_p = "abatement" if country == "Hong Kong" & week > 16; // wk15=77 wk16=17 wk17=8 wk18=3
replace end_p = "abatement" if country == "Korea" & week > 16; // wk15=233 wk16=129 wk17=69 wk18=52
replace end_p = "abatement" if country == "Taiwan" & week > 16; // wk15=20 wk16=29 wk17=7 wk18=9

/*****************************************************************************/
/* 3. TABLE A1. Numbers of Editorials by Newspaper */
/*****************************************************************************/

tab newspaper end_p;


/*****************************************************************************/
/* 4. TABLE A3. Summary Statistics of Independent Variables */
/*****************************************************************************/

sort country;
sum alarm health economic social political blame praise action_p action_s;
by country: sum alarm health economic social political blame praise action_p action_s;


/*****************************************************************************/
/* 5. TABLE A4. Logit Table: Impact of abatement period on tone and framing */
/*****************************************************************************/

/* Weighing Articles
I generate a weights variable so crisis breakout and abatement period editorials are weighted proportionally
--50% during the breakout and 50% abatement for each country.
Taiwan and Hong Kong articles were weighted quite heavily since I coded 55 reports from each
of these papers (compared to 110 for China and Korea). The result is that each case has the
same effect on the data, during the breakout and abatement periods. */

gen country_end_p = country + end_p;
sort country_end_p;
by country_end_p: generate a_tally = _N;
gen a_weight = 55 / a_tally;
gen abatement = 0;
replace abatement = 1 if end_p == "abatement";

/* Some local vars for the following analysis */
local marginsplot_baropts
	yscale(range(-.02 1) noline)
	ylabel(0(.05)1, labsize(3) angle(0))
  yline(0(.01)1, lwidth(vthin) lcolor(gs14))
  ytitle("") xtitle("")
  recast(bar)
  plotopts(barw(.7) bcolor("ltblue"))
	level(90)
  /* nodraw*/;

local gph_combine_opts
	imargin(l=0 r=4 b=10 t=5)
	ycommon
	ysize(8)
	xsize(10)
  iscale(*.6)
	plotregion(style(none));

local otreg_opt
	bdec(2) sdec(2) rdec(2) symbol(***, **, *) label;

/* Table A3. Logit Table */
logit alarm abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2)
title("Logit Model: Change in content in the abatement period") replace;
logit health abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit social abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit economic abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit political abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit blame abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit praise abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit action_p abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit action_s abatement [pw=a_weight], level(90);
outreg2 using table_time, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2) excel;

/*****************************************************************************/
/* 6. FIGURE 2. Predicted probabilities of tone and framing levels during the breakout and abatement periods */
/*****************************************************************************/

logit alarm abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(alarm, replace)
  title(alarm);

logit health abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(health, replace)
  title(health);

logit social abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(social, replace)
  title(social);

logit economic abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(economic, replace)
  title(economic);

logit political abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(political, replace)
  title(political);

logit blame abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(blame, replace)
  title(blame);

logit praise abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(praise, replace)
  title(praise);

logit action_p abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(action_p, replace)
  title(action_p);

logit action_s abatement [pw=a_weight], level(90);
margins, at(abatement =(0(1)1)) vsquish level(90);
marginsplot, `marginsplot_baropts'
  xlabel(0 "Cr." 1 "PCr.")
  name(action_s, replace)
  title(action_s);

graph combine
	alarm health social economic political blame praise action_p action_s,
	`gph_combine_opts' 	rows(1) name(time_mp, replace)
	title("Predicted probabilities of crisis breakout and abatement", size(3));

graph export "time_mp.pdf", as(pdf) replace;

/*****************************************************************************/
/* 7. TABLE 1: Alarming Tone Across Cases */
/*****************************************************************************/

bysort country: tabstat alarm, format(%9.2f) by(end_p);
bysort country: tabulate end_p alarm, chi2;

/*****************************************************************************/
/* 8. TABLE 2: Consequence Frames Across Cases */
/*****************************************************************************/

bysort country: tabstat health, format(%9.2f) by(end_p);
bysort country: tabulate end_p health, chi2;
bysort country: tabstat social, format(%9.2f) by(end_p);
bysort country: tabulate end_p social, chi2;
bysort country: tabstat economic, format(%9.2f) by(end_p);
bysort country: tabulate end_p economic, chi2;
bysort country: tabstat political, format(%9.2f) by(end_p);
bysort country: tabulate end_p political, chi2;

/*****************************************************************************/
/* 9. TABLE 3: Responsibility Frames Across Cases */
/*****************************************************************************/

bysort country: tabstat blame, format(%9.2f) by(end_p);
bysort country: tabulate end_p blame, chi2;
bysort country: tabstat praise, format(%9.2f) by(end_p);
bysort country: tabulate end_p praise, chi2;

/*****************************************************************************/
/* 10. TABLE 4: Action Frames Across Cases */
/*****************************************************************************/

bysort country: tabstat action_p, format(%9.2f) by(end_p);
bysort country: tabulate end_p action_p, chi2;
bysort country: tabstat action_s, format(%9.2f) by(end_p);
bysort country: tabulate end_p action_s, chi2;

/*****************************************************************************/
